{meta_html js $j_basepath.'design/back/js/popup.js'}

<div id="main_container">
    {$oZoneHeader}
    <div class="main_content">
        {$oZoneTopMenu}
        <div class="center_content">  
            <div class="left_content">
                {$oZoneLeftMenu}
                {if isset ($formule) }
                    {$formule->content}
                {/if}
                <div style="clear:both;height:10px;">&nbsp;</div>
                <form action="{jurl 'annonce~BoAnnonce:sauvegarder'}" method="post" id="editAnnonce" name="editAnnonce">
                    <div class="submitForm" >
                        {if isset($idOccasion)}
                        <input  id ="modifier-annonce" name="action"  class="modifier" title="Modifier" type="submit" value="" style="float:left; margin-left:0;"  />
                        <a title="Valider" href="{jurl 'annonce~BoAnnonce:modifyStatus',array('idOccasion'=>$idOccasion,'status'=>1)}" class="bt_green" style="float:left; clear:none; margin:3px 5px 0;"><span class="bt_green_lft"></span><strong>Valider</strong><span class="bt_green_r"></span></a><br />
                        <a title="Archiver" href="{jurl 'annonce~BoAnnonce:modifyStatus',array('idOccasion'=>$idOccasion,'status'=>2)}" class="bt_green" style="float:left;"><span class="bt_green_lft"></span><strong>Archiver</strong><span class="bt_green_r"></span></a>
                        <a title="Supprimer" href="#" class="bt_red modifadvert" style="float:left; clear:none;"><span class="bt_red_lft"></span><strong>Supprimer</strong><span class="bt_red_r"></span></a>
                        {else}
                            <span class="valide-annonce" style="float:right; margin:0;">
                                <input  name="action"  id ="valider" class="valider" title="Valider" type="submit" value=""/><br />
                             </span>
                        {/if}
                        <a title="Annuler" href="{jurl 'annonce~BoAnnonce:index'}" class="bt_green" style="clear:none; margin-top:0; margin-right:51px;"><span class="bt_green_lft"></span><strong>Annuler</strong><span class="bt_green_r"></span></a>
                    </div>
            </div>
    
            <div class="right_content">
               <h2>{if (isset($annonceSelected))}Modifier{else}Ajouter{/if} une annonce</h2> 
                    <input type="hidden" name="id" value="" />
                    <input type="hidden" name="idFormule" value="{$formule->id}" />
                    <input type="hidden" name="origine" value="{$origine}" />
                    <input type="hidden" name="garantie" value="{$garantie}" />
                    <input type="hidden" name="source" value="{$origine}" />
                    {if isset($annonceSelected)}<input type="hidden" name="annonce_id" value="{$idOccasion}" />{/if}
                    {if isset($idOccasion)}<input type="hidden" name="idOccasion" value="{$idOccasion}" />{/if}
                     
                    {$oZoneCaracteristiqueVoiture}
                    {$oZoneAnnonceCoordonnees}
                    {$oZoneAnnonceEquipements}
                    {$oZoneCommentaire}
                    {$oZoneAnnoncePhoto}
                    <div id="partenaire" style="background-color:#ECF8FD;height:35px;padding:5px; margin-bottom:15px;">
                            <dl>
                                <dt><label>Validité: </label></dt>
                                <dd><input type="radio" value="1" name="validite" {if (isset($voiture) && ($voiture->Occas_Valide == 1))}checked="checked"{/if}/>Oui
                                     <input type="radio" value="0" name="validite"{if (isset($voiture) && ($voiture->Occas_Valide == 0))}checked="checked"{/if}/>Non
                                     <input type="radio" value="2" name="validite"{if (isset($voiture) && ($voiture->Occas_Valide == 2))}checked="checked"{/if}/>Archivée
                                     <input type="radio" value="3" name="validite"{if (isset($voiture) && ($voiture->Occas_Valide == 3))}checked="checked"{/if}/>Supprimée
                                </dd>

                                <dt><label>Référence : </label></dt>
                                <dd><input type="text" value="{if (isset($voiture) && ($voiture->Occas_Reference))}{$voiture->Occas_Reference}{/if}" name="reference"/></dd>
                            </dl>
                     </div>
                </form>
            </div><!-- end of right content-->
        </div>   <!--end of center content -->               

        <div class="clear"></div>
    </div> <!--end of main content-->
    <div class="footer">
    </div>

</div>

 {literal}
        <style type="text/css">
            p label {width:400px;margin-right:20px;}
            p span {float:right;margin-right:350px;}
            .error input {border:1px solid red;}
            .error textarea {border:1px solid red;}
            .errorlist li {font-size: 0.8em;}
            div#ajaxload {border:solid 2px #38AFD9;width:600px;}
                 /* ::: popin ::: */
#masque{position:absolute; top:0; left:0; display:none; cursor:wait; background:black; z-index:799; }
.pop-up{display:block;  height:auto; left:0; position:absolute; top:-1000px; width:60%; z-index:800; background:#fff; padding:25px; border:5px solid #cdcdcd;}
a.showpopin{position:absolute; right:10px; top:235px; width:38px; height:40px;}

        </style>

    <script type="text/javascript">
        $(function(){

             //contrôle des champs obligatoires  lors  de l'ajout 
            $('#valider').click(function (i) {
                bErrorF = bErrorNum = false;
                
                
                $('.requiredB').each(function (i) {
                    if (!$(this).val() || $(this).val() == "" || $(this).val() == "0")
                    {
                        $(this).css('border', 'solid 1px red');
                        $(this).addClass('foc');
                        bErrorF = true;
                    }
                    else 
                    {
                        $(this).removeClass('foc');

                       $(this).css('border', 'solid 1px #C4C4C4');
                    }
                });

                // controle des champs numerique : km et prix
                $('.numerique').each(function () {
                    _valeur         = $(this).val();
                    Expression      = new RegExp("^\\d\\d*$");
                    ExpressionCheck = Expression.test(_valeur);
                    if (_valeur && !ExpressionCheck)
                    {
                        $(this).css('border', 'solid 1px red');
                        bErrorNum = true;
                    }
                    else if(_valeur)
                    {
                       $(this).css('border', 'solid 1px #C4C4C4');
                    }
                });

                countError = 0;

                $('.spc-case').each(function () {
                    _current = $(this);
                    value    = _current.val();
                    if (!value )
                    {
                        // erreur
                        countError ++;
                    }
                    else 
                    {
                        //06 09 88 55 66
                        if (value.length != 10)
                        {
                             _current.css('border', 'solid 1px red');
                             bErrorF = true;
                        }
                        /*else
                        {
                            _tel1 = value.substring(2,3);
                            _tel2 = value.substring(5,6);
                            _tel3 = value.substring(8,9);
                            _tel4 = value.substring(11,12);
                            if (_tel1 != ' ' || _tel2 != ' ' || _tel3 != ' ' || _tel4 != ' ')
                            {
                                _current.css('border', 'solid 1px red');
                                bErrorF = true;
                            }
                            else
                            {
                                _current.css('border', 'none');
                            }
                        }
                        */
                    }

                });
                if (countError == 3)
                {
                    $('#dom').focus();
                    $('#dom').css('border', '1px solid red');
                    bErrorF = true;
                }

                if (bErrorF || bErrorNum) {
                  $('.foc').focus();

                  return false;
                } else {
                 document.forms["editAnnonce"].submit();
                }
            });

        // controle des champs obligatoires lors de modification 
            $('#modifier-annonce').click(function () {

                bErrorF = false;
               $('.requiredB').each(function () {
                if (!$(this).val())
                {
                    $(this).css('border', 'solid 1px red');
                    bErrorF = true;
                }
                 else 
                {
                   $(this).css('border', 'solid 1px #C4C4C4');
                }
            });

             countError = 0;

            $('.spc-case').each(function () {
                value = $(this).val();
                if (!value)
                {
                    countError ++;
                    $('.spc-case').focus();

                }
                else 
                {
                    $(this).css('border', 'none');
                }
            });
            if (countError == 3)
            {
                $('#dom').focus();
                $('#dom').css('border', '1px solid red');
                bErrorF = true;
            }
            else
            {
                $('#dom').css('border', 'none');
            }

            if (bErrorF)
            {
                $('.requiredB').focus();

                return false;
            } 
        });

    $( "#datepicker" ).datepicker({dateFormat: 'dd/mm/yy'});

    // form validation
    var test = $("#editAnnonce");
    test.validation();
    test.submit(function(e) {
        $("#valid-form").remove();
        if(test.validate()) {
            document.forms["editAnnonce"].submit();
        }
        e.preventDefault();
    });
});

        // remove space in tel field
        function nospaces(t){
            if(t.value.match(/\s/g)){
                t.value=t.value.replace(/\s/g,'');
            }
        }
    </script> 
{/literal}


    <div id="popvisuadvertmodif" class="pop-up cgv">
<a href="#" class="close" style="float:right;margin-right:20px;">Fermer</a>
        <form action="{jurl 'annonce~BoAnnonce:modifyStatus'}" method="post" style="width:325px;margin:20px auto;">
        {if isset($idOccasion)}
            <input type="hidden" name="idOccasion" value="{$idOccasion}"/>
        {/if}
        <input type="hidden" name="status" value="3"/>
            <fieldset>
                <p> 
                    <label> Mail du vendeur : </label>
                    {if isset($vendeur)}
                        <input type="text" name="mail_vendeur" value="{$vendeur->Vendeur_Email}" style="width:195px;" readonly />
                    {/if}
                </p>
                <h2>Veuillez choisir le mail à envoyer</h2>
                <p>
                    <select name='mailtpl'>
                        <option value="0"></option>
                        {foreach $templatemail as $item}
                            <option value="{$item->mail_id}">{$item->mail_name}</option>
                        {/foreach}
                    </select>
                </p>
                <p> 
                    <input type="submit" name="valider" value="OK" />
                </p>
            </fieldset>
        </form>
    </div>


<div id="masque"></div>  
